var pageSize = 10,pageNum = 1,canScroll=false,isload = false,hpLogin_token = window.localStorage.getItem("hpLogin_token");;

getBrokerage();

function getBrokerage(isload){
  $.ajax({
      type:'POST',
      url:address+'/broker/listBrokerage.do?format=true',
      data:{
        "pageNum":pageNum,
        "pageSize":pageSize,
        "hpLogin_token":hpLogin_token
      },
      dataType:'json',
      success:function(result){
        if(result.status ==200 ){
          $("#myCard").text(result.data.nickname);
          $("#myphoto").attr("src",result.data.image);
          $("#clientNum").text(result.data.customerNumber);
          $("#brokerage").text(result.data.totalBrokerage);
        }
        if(result.status ==200 && result.data.list !=""){
            var html = "";
            $.each(result.data.list,function(index,info){
                var img = info.image ? info.image+'&size=180x150' : noImg ;
                html += '<div class="list p5 b-b db">'+
                  '<dl>'+
                    '<dt><img src="'+img+'" class="pic"></dt>'+
                    '<dd>'+
                      '<div class="name l-h20 black f-s14 p-t5">'+info.name+'</div>'+
                      '<p class="black l-h24"><span class="fr orange b f-s14">'+info.brokerage+'元</span><span class="gray">'+info.timeStr+'</span></p>'+
                      '<div class="label orange m-t5"><span>'+info.desc+'</span></div>'+
                    '</dd>'+
                  '</dl>'+
              '</div>';
            });
            if(isload){
              $("#Brokerage").append(html);
            }else{
              $("#Brokerage").html(html);
            }
            canScroll =true;
        }else{
          canScroll =false;
          var html = '<div class="nodata">没有数据</div>';
          $("#Bargain").html(html);
        }
      },
      error:function(result){
        message(result.message)
      }
  })
}

//滚动加载
$(window).scroll(function(){
    var scrollT = document.documentElement.scrollTop || document.body.scrollTop,
    clientH = $(window).height(),
    docH = $(document).height();
    var $loading = $(".loading");
    if(scrollT >= (docH - clientH) && canScroll==true){
      canScroll = false;
      pageNum ++;
      $loading.show();
      isload = true;
      getBrokerage(isload);

    }else{
      $loading.hide();
    }
})
